package com.example.xuyuli.repository.impl;


import com.example.xuyuli.entity.User;
import com.example.xuyuli.repository.UserRepository;
import com.example.xuyuli.utils.JDBCTools;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserRepositoryimpl implements UserRepository {
    public User login(String name,String password){
        Connection connection = JDBCTools.getConnection();
        System.out.println(connection);
        String sql = "select * from student where name = ? and password = ?";
        PreparedStatement statement = null;
        ResultSet resultSet = null;
        User user = null;
        try {
            statement = connection.prepareStatement(sql);
            statement.setString(1,name);
            statement.setString(2,password);
            resultSet = statement.executeQuery();
            if(resultSet.next()){
                user = new User(resultSet.getString(1),resultSet.getString(2),resultSet.getString(3));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            JDBCTools.release(connection,statement,resultSet);
        }
        return user;

    }





}
